package com.glsc.ngateway.common.base.repo.mysql.gateway.oaflow;

import com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow.TOaFlowSyncLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Repository
public interface TOaFlowSyncLogRepository extends JpaRepository<TOaFlowSyncLog, Long> {

    /**
     * 同步流程后，为log填写requestId，并修改其状态
     *
     * @param workFlowId
     * @param taskId
     * @param requestId
     */
    @Transactional
    @Modifying
    @Query(value = " update TOaFlowSyncLog l " +
            " set l.requestId = :requestId, l.status = :status" +
            " where l.workflowId = :workFlowId and l.taskId = :taskId ")
    void updateStatusAndRequestId(@Param("workFlowId") String workFlowId,
                                  @Param("taskId") String taskId,
                                  @Param("requestId") Integer requestId,
                                  @Param("status") String status);

    TOaFlowSyncLog findByWorkflowIdAndTaskId(String workflowId, String taskId);

    TOaFlowSyncLog findByRequestId(Integer requestId);

    List<TOaFlowSyncLog> findAllByStatusIn(List<String> status);

    List<TOaFlowSyncLog> findAllByTaskIdIn(List<String> taskIds);
}
